package com.dabai.playlistdown.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.bumptech.glide.Glide;
import com.dabai.playlistdown.R;
import com.dabai.playlistdown.pojo.MusicInfo;

import java.util.List;

public class MusicAdapter extends ArrayAdapter {

    Context context;
    private final int resourceId;
    private MusicInfo musicInfos;

    public MusicAdapter(Context context, int textViewResourceId, List<MusicInfo> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        musicInfos = (MusicInfo) getItem(position); // 获取当前项的Fruit实例
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象
        ImageView pic = view.findViewById(R.id.pic1);//获取该布局内的图片视图
        TextView title = view.findViewById(R.id.title1);//获取该布局内的文本视图
        TextView sub = view.findViewById(R.id.sub1);//获取该布局内的文本视图

        Glide.with(context)
                .load(musicInfos.getPic())
                .centerCrop()
                .into(pic);

        title.setText(musicInfos.getTitle());//为文本视图设置文本内容
        sub.setText(musicInfos.getAuthor());//为文本视图设置文本内容


        return view;
    }

}
